package com.example.demo.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.model.Book;
import com.example.demo.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface BookMapper extends BaseMapper<Book> {
    @Select("SELECT * FROM book WHERE book_id = #{bookId}")
    Book findBookById(Long bookId);

    @Update("UPDATE book SET stock = stock - 1, status = 'BORROWED' WHERE book_id = #{bookId}")
    int borrowBookWithLock(Long bookId);

    @Update("UPDATE book SET stock = stock + 1, status = 'AVAILABLE' WHERE book_id = #{bookId}")
    void returnBook(Long bookId);
}